
class HcjlbProxy extends ResourceProxyBase {
    public static NAME: string = "HcjlbProxy";//必须和excel导出文件一致
    public static Proxy: HcjlbProxy = null;
    public constructor() {
        super(HcjlbProxy.NAME);
    }
    public static getProxy() {
        if (!HcjlbProxy.Proxy) {
            HcjlbProxy.Proxy = new HcjlbProxy();
        }
        return HcjlbProxy.Proxy;
    }
    //登陆
    public login(data: Object) {
        HcjlbVO.VO = null;
        HcjlbVO.getVo().lUserScore = GameVO.getVo().lUserScore;
    }
    //获取房间配置信息，获取完成后发送匹配玩家请求
    public getRoomInfo(data: Object) {
        HcjlbVO.getVo().dwServerRule = data["dwServerRule"];
        HcjlbVO.getVo().wChairCount = data["wChairCount"];
        HcjlbVO.getVo().wServerType = data["wServerType"];
        HcjlbVO.getVo().wTableCount = data["wTableCount"];
    }
    //用户进入广场 携带用户所有数据 3-100
    public userJoinSquare(data: Object) {
        let user = data["tagMobileUserInfoHead"];
        HcjlbVO.getVo().userInfo[user.dwUserID] = user;;//广场所有人存入集合
        this.userJoinRoom();
    }
    //用户战绩信息刷新 包括金币 3-101
    public getUserInfo(data: Object) {
        let UserScore = data["UserScore"];
        let dwUserID = data["dwUserID"];
        let lScore = UserScore["lScore"];
        let user = HcjlbVO.getVo().userInfo[dwUserID];
        if (user) {
            user.lScore = lScore;
        }
        this.userJoinRoom();
    }
    //用户状态变更 入座，离开 3-102
    public userStateModify(data: Object) {
        //用户状态发生改变从缓存的所有用户中找到该用户改变其座位
        let dwUserID = data["dwUserID"];
        let wTableID = data["tableId"];
        let wChairID = data["wChairID"];
        let cbUserStatus = data["cbUserStatus"];
        let user = HcjlbVO.getVo().userInfo[dwUserID]
        if (user) {
            user.wTableID = wTableID;
            user.wChairID = wChairID;
            user.cbUserStatus = cbUserStatus;
        }
        this.userJoinRoom();
    }

    public userJoinRoom() {
        HcjlbVO.getVo().initUserInof();
        //状态改变完毕后从所有玩家中找自己是否已入座，若自己入座，则找是否跟自己同桌的用户，将其显示到桌子对面
        let user = HcjlbVO.getVo().userInfo[GameVO.getVo().dwUserID]
        if (user) {
            HcjlbVO.getVo().wTableId = user.wTableID;
            HcjlbVO.getVo().wChairId = user.wChairID;
            HcjlbVO.getVo().status = user.cbUserStatus
            HcjlbVO.getVo().lUserScore = user.lScore
        }
        //我入座找对手
        if (HcjlbVO.getVo().wTableId != null && HcjlbVO.getVo().wTableId != 65535) {
            HcjlbVO.getVo().wTableId_up = HcjlbVO.getVo().wTableId;
            //根据我所在椅子确定其他玩家在桌面坐哪个位置
            for (let i in HcjlbVO.getVo().userInfo) {
                let user = HcjlbVO.getVo().userInfo[i]
                if (user.wTableID == HcjlbVO.getVo().wTableId &&
                    user.dwUserID != GameVO.getVo().dwUserID) {//跟我坐一桌的就是对手
                    HcjlbVO.getVo().playerNumber++;
                }
            }
            game.AppFacade.instance.sendNotification(PanelNotify.WJL.JOIN_ROOM);
        } else {
            if (HcjlbVO.getVo().wTableId_up != null && HcjlbVO.getVo().wTableId == 65535) {
                //上次有座位此次没座位说明被踢了
                SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.HCJLB);
            }
        }
    }

    //100-101 中途加入
    public dataRecovery(data: Object) {

    }

    //玩家下注
    public userBets(data: Object) {
        HcjlbVO.getVo().ItemBetAmount = data["ItemBetAmount"];
        HcjlbVO.getVo().wBetItem = data['wBetItem'];
        HcjlbVO.getVo().wBetAmount = data['wBetAmount'];
        HcjlbVO.getVo().wUserID = data['wUserID'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.USER_BETS);
    }
    //场景信息
    public sceneInfo(data: Object) {
        HcjlbVO.getVo().cBankName = data['cBankName']; //庄家名称
        HcjlbVO.getVo().llBankerScore = data['llBankerScore']; //庄家金币
        HcjlbVO.getVo().wApplyBankerNum = data['wApplyBankerNum']; //申请庄家数
        HcjlbVO.getVo().sItemOdds = data['sItemOdds']; //wBetItem 下注项目 wOdds 项目赔率
        HcjlbVO.getVo().BankerLowestProperty = data['BankerLowestProperty']; //庄家最低金币
        HcjlbVO.getVo().wRecordNumber = data['wRecordNumber']; //历史个数
        HcjlbVO.getVo().wDrawRecord = data['wDrawRecord']; //开奖历史
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.SCENE_INFO);
    }
    //开奖
    public lottery(data: Object) {
        HcjlbVO.getVo().dwTimeLeave = data['wTimeLeave']; //剩余时间
        HcjlbVO.getVo().lotterywWhichOne = data['wWhichOne']; //本次选中哪一个
        HcjlbVO.getVo().lotterydwBankerScore = data['dwBankerScore']; //庄家本局赢的金币
        HcjlbVO.getVo().lotterywBankOnJobTimes = data['wBankOnJobTimes']; //庄家坐庄次数
        HcjlbVO.getVo().lotteryPlayerInfoArray = data['PlayerInfoArray']; //cPlayerName 名字 llProfit盈利
        HcjlbVO.getVo().lotteryllTotalPfofit = data['llTotalPfofit']; //玩家本局总盈利
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.LOTTERY);
    }
    //上庄列表 
    public continueCard(data: Object) {
        HcjlbVO.getVo().cbApplyNum = data['cbApplyNum'];
        HcjlbVO.getVo().sApplyBanker = data['sApplyBanker'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.CONTINUE_CARD);
    }
    //申请上庄
    public applyBanker(data: Object) {
        HcjlbVO.getVo().dwUserid2 = data['dwUserid'];
        HcjlbVO.getVo().successful = data['successful'];
        HcjlbVO.getVo().wApplyBankerNum = data['wApplyBankerNum'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.APPLY_BANKER);
    }
    //取消上庄
    public cancelCard(data: Object) {
        let dwUserid = data["dwUserid"];
        if (dwUserid == HcjlbVO.getVo().dwUserid2) {
            HcjlbVO.getVo().cancelCard = data;
            game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.CANCEL_CARD);
        }
    }
    //庄家信息
    public switches(data: Object) {
        HcjlbVO.getVo().lotterywBankOnJobTimes = data['dwmBankerOnJobTimes'];
        HcjlbVO.getVo().dwUserID = data['dwUserID'];
        HcjlbVO.getVo().cBankName = data['cBankName'];
        HcjlbVO.getVo().llBankerScore = data['llBankerScore'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.BANKER_INFO);
    }
    //押注状态
    public betState(data: Object) {
        HcjlbVO.getVo().ItemBetAmount = data['sItemAmount'];
        HcjlbVO.getVo().dwTimeLeave = data['dwTimeLeave'];
        HcjlbVO.getVo().sBetingItemInfo = data['sBetingItemInfo'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.BET_STATE);
    };
    //开奖状态
    public lotteryState(data: Object) {
        HcjlbVO.getVo().dwTimeLeave = data['dwTimeLeave'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.LOTTERY_STATE);
    };
    //空闲状态
    public freeState(data: Object) {
        HcjlbVO.getVo().dwTimeLeave = data['dwTimeLeave'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.FREE_STATE);
    };
    //开始下注
    public startBet(data: Object) {
        HcjlbVO.getVo().dwTimeLeave = data['cbTimeLeave'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.START_BET);
    }
    //用户信息
    public userInfo(data: Object) {
        HcjlbVO.getVo().tagMobileUserInfoHead = data['tagMobileUserInfoHead'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.USER_INFO);
    }
    //用户分数
    public userScore(data: Object) {
        HcjlbVO.getVo().userid = data['dwUserID'];
        HcjlbVO.getVo().UserScore = data['UserScore'];
        game.AppFacade.instance.sendNotification(PanelNotify.HCJLB.USER_SCORE);
    }
}
